package com.roncoo.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.order.entity.EduWithdrawals;
import com.roncoo.order.dao.EduWithdrawalsMapper;
import com.roncoo.order.service.IEduWithdrawalsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuechuanhao
 * @since 2021-04-10
 */
@Service
public class EduWithdrawalsServiceImpl extends ServiceImpl<EduWithdrawalsMapper, EduWithdrawals> implements IEduWithdrawalsService {

    @Resource
    private EduWithdrawalsMapper eduWithdrawalsMapper;

    @Override
    public IPage<List<Map>> findAllById(Integer lecturerId, Page page) {
        QueryWrapper<EduWithdrawals> eduWithdrawalsQueryWrapper = new QueryWrapper<>();
        eduWithdrawalsQueryWrapper.eq("edu_withdrawals.lecturer_id",lecturerId);
        Page page1 = eduWithdrawalsMapper.selectPage1(page, eduWithdrawalsQueryWrapper);
        return page1;
    }

    @Override
    public Map money(String id) {
        Map map = new HashMap();
        if(eduWithdrawalsMapper.selectAllMoney(id)!=null){
            map.put("AllMoney",eduWithdrawalsMapper.selectAllMoney(id));
        }else {
            map.put("AllMoney",0);
        }
        if(eduWithdrawalsMapper.selectTiMoney(id)!=null){
            map.put("TiMoney",eduWithdrawalsMapper.selectAllMoney(id)-eduWithdrawalsMapper.selectTiMoney(id));
        }else {
            map.put("TiMoney",0);
        }
        return map;
    }
}
